Skip to content

dataconnect(chore): add logic to integrate network state changes with exponential backoff logic#8421

Draft
dconeybe wants to merge 7 commits into
mainfrom
dconeybe/dataconnect/netcon
Draft

dataconnect(chore): add logic to integrate network state changes with exponential backoff logic#8421
dconeybe wants to merge 7 commits into
mainfrom
dconeybe/dataconnect/netcon

Conversation

@dconeybe

@dconeybe dconeybe commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This PR adds a mechanism to monitor network connectivity changes on Android (using ConnectivityManager) and emit events when the network appears to be restored. This allows downstream connection retry backoff mechanisms to abort retry delays and attempt to reconnect immediately when network connectivity is restored.

NOTE: This PR does NOT affect the exponential backoff mechanism. That will come in a subsequent PR. This PR ONLY adds the functionality that will be used by the exponential backoff logic.

Highlights

  • Network Connectivity Flow: Introduced networkConnectivityRestoredFlow which creates a cold Flow of NetworkConnectivityRestored events. It monitors Android network changes on API 23+, tracking available and validated networks, and only signaling on meaningful connectivity transitions.
  • Coroutine Signaling Improvements: Added a signalIfNotNull extension function to ConflatedSignal to simplify signaling with nullable values.
  • Testing Utilities and Property-based Testing: Added mutable primitive wrappers (MutableBoolean, MutableInt, etc.) and Arb.Companion.any() generators for Kotest to facilitate robust property-based testing of dynamic objects and collections.
Changelog
  • CHANGELOG.md
    • Updated the query subscriptions exponential backoff entry to reference this PR.
  • NetworkConnectivityRestoredFlow.kt
    • Added networkConnectivityRestoredFlow using ConnectivityManager.NetworkCallback with support for different API levels (using registerDefaultNetworkCallback on API 24+ and custom requests on API 23) to emit NetworkConnectivityRestored signals.
  • ConflatedSignal.kt
    • Added ConflatedSignal.signalIfNotNull extension function.
  • NetworkConnectivityRestoredFlowUnitTest.kt
    • Added unit tests for networkConnectivityRestoredFlow to verify callback scenarios under various network status, capability, and validation changes.
  • ConflatedSignalUnitTest.kt
    • Added tests for signalIfNotNull.
  • MutablePrimitives.kt
    • Added mutable primitive wrapper classes (MutableBoolean, MutableByte, MutableShort, MutableInt, MutableLong, MutableChar, MutableFloat, MutableDouble, MutableReference).
  • any.kt
    • Added Arb.Companion.any generator for Kotest property-based tests.
  • mutableprimitives.kt
    • Added Kotest Arb generators for the new mutable primitives.
  • MutablePrimitivesUnitTest.kt
    • Added comprehensive tests for mutable primitives and their generators.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@dconeybe

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a cold Flow to monitor network connectivity changes and signal when connection restoration is possible, accompanied by comprehensive unit tests. Additionally, it introduces mutable primitive wrappers and custom property-based test generators (like Arb.any) to the test utilities. The review feedback highlights a logic error in the Arb.any generator where extras are incorrectly duplicated within a loop, as well as a minor formatting typo in the changelog.

Comment thread firebase-dataconnect/CHANGELOG.md Outdated
dconeybe added 2 commits July 14, 2026 22:05
#8421 (comment)

The `addAll(extras)` call is inside the `forEach` loop of `allScalarArbFactories`. This causes the `extras` list to be duplicated and added to `scalarArbs` multiple times (once for each scalar factory), which skews the random distribution of `Arb.any` heavily towards the extras. Moving it outside the loop resolves this issue.

```suggestion
  val scalarArbs = buildList {
    allScalarArbFactories.forEach {
      if (it.type !in excludes) {
        add(it.factory())
      }
    }
    addAll(extras)
  }
```
#8421 (comment)

There is a typo in the parentheses formatting. The second line has an extra opening parenthesis `(` before the pull request link.
@github-actions

Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant